def hot_potato(name_ls: list, num: int) -> str:
    """约瑟夫问题

    Args:
        name_ls (list): 人员姓名列表
        num (int): 第几个人出局

    Returns:
        str: 幸存者
    """
    from pythonds.basic import Queue

    name_queue = Queue()
    for name in name_ls:
        name_queue.enqueue(name)

    while len(name_queue) > 1:
        for m in range(num - 1):
            name_queue.enqueue(name_queue.dequeque())
        name = name_queue.dequeque()
        # print(name)

    return name_queue.dequeque()


# 利用链表实现
from pythonds.linklist import UnorderedList


class JosephList(UnorderedList):
    def __init__(self, name_ls: list):
        super().__init__()
        if len(name_ls) == 0:
            self.is_circle = False
        else:
            for name in name_ls:
                self.append(name)

            self._tail.next.next = self._head.next
            self.is_circle = True

    def erase(self, m=7):
        cur = self._head
        while self.size > 1:
            for c in range(m - 1):
                cur = cur.next

            t = cur.next
            # print("{} is out.".format(t.data))
            cur.next = t.next
            del t
            self._size -= 1

        print("{} is lucky!".format(cur.data))
